package net.zjitc.service.user.userServiceImpl;

import net.zjitc.dao.user.UserDao;
import net.zjitc.dao.user.userDaoImpl.UserDaoImpl;
import net.zjitc.domain.User;
import net.zjitc.service.user.UserService;

/**
 * Created by hasee on 2017/10/20.
 */
public class UserServiceImpl implements UserService {
    @Override
    public User login(String username, String password) {
        UserDao dao = new UserDaoImpl();
        User user = dao.findByUsername(username);
        if (user!=null&&password.equals(user.getPassword())){
            return user;
        }
        return null;
    }

    @Override
    public User logon(String username, String password, String phone) {
        UserDao dao = new UserDaoImpl();
        User user = dao.findByUsername(username);
        if(user==null){
            User newUser = new User();
            newUser.setUsername(username);
            newUser.setPassword(password);
            newUser.setPhone(phone);
            dao.insert(newUser);
            return newUser;
        }
        return null;
    }
}
